using UnityEngine;
using System.Collections.Generic;


public class UIButtonEx : UIButton
{
    SpriteEx normalSpriteEx;
    public SpriteEx disabledSpriteEx;
    public SpriteEx pressedSpriteEx;
    public SpriteEx hoverSpriteEx;

    UI2DSpriteEx uiSprite;

    protected override void OnInit ()
    {
        base.OnInit();
        uiSprite = mWidget as UI2DSpriteEx;
        if (uiSprite != null) normalSpriteEx = uiSprite.spriteEx;
    }

    protected override void SetSprite (UnityEngine.Sprite sp)
    {
        if (sp != null && uiSprite != null && uiSprite.sprite2D != sp)
        {
            bool setted = false;
            if (normalSpriteEx != null && normalSpriteEx.sprite == sp)
            {
                uiSprite.SetSprite(normalSpriteEx);
                setted = true;
            }
            else if (disabledSpriteEx != null && disabledSpriteEx.sprite == sp)
            {
                uiSprite.SetSprite(disabledSpriteEx);
                setted = true;
            }
            else if (pressedSpriteEx != null && pressedSpriteEx.sprite == sp)
            {
                uiSprite.SetSprite(pressedSpriteEx);
                setted = true;
            }
            else if (hoverSpriteEx != null && hoverSpriteEx.sprite == sp)
            {
                uiSprite.SetSprite(hoverSpriteEx);
                setted = true;
            }

            if (!setted)
            {
                base.SetSprite(sp);
            }
            else
            {
                if (pixelSnap) uiSprite.MakePixelPerfect();
            }
        }
    }
}
